import React, { Component } from "react";
import axios from "axios";
import { NavLink, Route } from "react-router-dom";
import Book from "./book";
export default class Index extends Component {
  constructor() {
    super();
    this.state = {
      navlist: []
    };
  }
  componentDidMount() {
    axios.get("http://localhost/8080/hot").then(res => {
      this.setState({
        navlist: res.data.data
      });
    });
  }
  render() {
    return (
      <div>
        {this.state.navlist.map(item => {
          return (
            <NavLink to={this.props.match.path + "/" + item.id} key={item.id}>
              {item.label}
            </NavLink>
          );
        })}
        {/* 动态路由 */}
        <Route path={this.props.match.path + "/:id"} component={Book} />
      </div>
    );
  }
}
